<template>
  <div class="sys-logininfor">
    <AppMainHeader>
      <el-row>
        <el-col :span="22">
          <SysLoginLogQueryForm @query="handleQuery"/>
        </el-col>
        <el-col :span="2" class="align-right">
          <el-button type="primary" @click="handleClean" v-hasPermi="['monitor:logininfor:remove']">
            清空
          </el-button>
        </el-col>
      </el-row>
    </AppMainHeader>

    <AppMainContent>
      <el-table v-loading="loading" :data="list">
        <el-table-column
          label="序号"
          align="center"
          prop="rowNumber"
          width="60"
        />
        <el-table-column label="用户名称" align="center" prop="userName"/>
        <el-table-column label="浏览器" align="center" prop="browser"/>
        <el-table-column label="操作系统" align="center" prop="os"/>
        <el-table-column
          label="登录状态"
          align="center"
          prop="status"
          :formatter="statusFormat"
        />
        <el-table-column
          label="操作信息"
          align="center"
          prop="msg"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="登录日期"
          align="center"
          prop="loginTime"
          width="180"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.loginTime) }}</span>
          </template>
        </el-table-column>
      </el-table>

      <Pagination
        v-show="total > 0"
        :total="total"
        :current.sync="queryParams.currPage"
        :size.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </AppMainContent>
  </div>
</template>

<script>
import { list, cleanLogininfor } from '@/api/monitor/logininfor'

import SysLoginLogQueryForm from '@/views/monitor/components/sys-login-log-query-form'

export default {
  name: 'SysLoginLog',
  components: {
    SysLoginLogQueryForm
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 状态数据字典
      statusOptions: [],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        currPage: 1,
        pageSize: 10,
        userName: undefined,
        status: undefined
      }
    }
  },
  created() {
    // this.getList()
    // this.getDicts('sys_common_status').then((response) => {
    //   this.statusOptions = response.data
    // })
  },
  methods: {
    /** 查询登录日志列表 */
    getList() {
      this.loading = true
      list(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.list = response.data
          this.total = response.page.total
          this.loading = false
        }
      )
    },
    // 登录状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status)
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    // handleSelectionChange(selection) {
    //   this.ids = selection.map(item => item.infoId)
    //   this.multiple = !selection.length
    // },
    /** 删除按钮操作 */
    // handleDelete(row) {
    //   const infoIds = row.infoId || this.ids;
    //   this.$confirm('是否确认删除访问编号为"' + infoIds + '"的数据项?', "提示", {
    //       confirmButtonText: "确定",
    //       cancelButtonText: "取消",
    //       type: "warning"
    //     }).then(function() {
    //       return delLogininfor(infoIds);
    //     }).then(() => {
    //       this.getList();
    //       this.msgSuccess("删除成功");
    //     })
    // },
    /** 清空按钮操作 */
    handleClean() {
      this.$confirm('是否确认清空所有登录日志数据项?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(function() {
          return cleanLogininfor()
        })
        .then(() => {
          this.getList()
          this.msgSuccess('清空成功')
        })
    }
    /** 导出按钮操作 */
    // handleExport() {
    //   const queryParams = this.queryParams;
    //   this.$confirm('是否确认导出所有操作日志数据项?', "提示", {
    //       confirmButtonText: "确定",
    //       cancelButtonText: "取消",
    //       type: "warning"
    //     }).then(function() {
    //       return exportLogininfor(queryParams);
    //     }).then(response => {
    //       this.download(response.msg);
    //     })
    // }
  }
}
</script>

<style lang="scss" scoped>
.sys-logininfor {
  width: 100%;
  height: 100%;
}
</style>
